package Dao.impl;

import Dao.messageDao;
import domain.message;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import uilts.C3P0utils;

import javax.xml.crypto.Data;
import java.sql.SQLException;
import java.util.List;

public class messageDaoImpl implements messageDao {
    C3P0utils c3P0utils=new C3P0utils();

    //计数
    @Override
    public int count(message message, String sql) throws SQLException {
        QueryRunner queryRunner = new QueryRunner(c3P0utils.getDataSource());
        domain.message query = queryRunner.query(sql, new BeanHandler<message>(message.class), message.getT_number());
        if(query.getCount()!=0){
            return query.getCount();
        }
        return 0;
    }

    //存值
    @Override
    public void insert(message message,String sql) throws SQLException {
        QueryRunner queryRunner = new QueryRunner(c3P0utils.getDataSource());
        queryRunner.update(sql,message.getT_time(), message.getT_ip(), message.getT_ie(), message.getT_number());
    }
}
